<?php
namespace addons\navigation\controllers;
use addons\navigation\models\NavigationModel;
use controllers\HomeBase;

class api extends HomeBase {
	protected $model = '';

	/**
	 * 获取所有导航
	 * @return string
	 * @author Colin <amcolin@126.com>
	 * @date 2022-01-22 下午4:21
	 */
	public function getNavs(){
		$this->model = new NavigationModel();
		$map = [
			'pid' => 0 ,
		];
		$field = 'id,title,url';
		$nav = $this->model->where($map)->order('sort desc')->field($field)->select();
		foreach ($nav as &$val){
			$val['child'] = $this->model->where(['pid' => $val['id']])->order('sort desc')->field('title,url')->select();
			unset($val['id']);
		}
		return success($nav);
	}
}